<?php

/**
 * 抽奖算法
 *
 * @param $arr
 *
 * @return array
 */
function choujiang($arr)
{
    $brr = array_column($arr,'num','name');
    $key = gailv($brr);
    
    $jiang = array_filter(array_map(function($v)use($key){
        if ($v['name'] == $key)
            return $v;
    },$arr));
    return $jiang;
    
}

/**
 * 抽中的概率
 *
 * @param $brr
 *
 * @return int|string
 */
function gailv($brr)
{
    $sum = array_sum($brr);
    foreach ($brr as $key=>$value)
    {
        $tmp = mt_rand(1,$sum);
        if ($value>$tmp)
        {
            return $key;
        }
        else
        {
            $sum -= $value;
        }
    }
}

$arr = [
    ['name' => 'a','num' => 100],
    ['name' => 'b','num' => 200],
    ['name' => 'c','num' => 300],
    ['name' => 'd','num' => 20],
];
var_dump(choujiang($arr));